package lang

import (
	"jvm/native"
	"jvm/rtda"
	"math"
)

func init() {
	native.Registers("java/lang/Float", []*native.NaMethod{
		{
			"floatToRawIntBits",
			"(F)I",
			floatToRawIntBits,
		}, {
			"intBitsToFloat",
			"(I)F",
			intBitsToFloat,
		},
	})
}

// public static native int floatToRawIntBits(float value);
func floatToRawIntBits(jFrame *rtda.JFrame) {
	value := jFrame.LocalVars().GetFloat(0)
	bits := math.Float32bits(value)
	jFrame.OperandStack().PushInt(int32(bits))
}

// public static native float intBitsToFloat(int bits);
func intBitsToFloat(jFrame *rtda.JFrame) {
	bits := jFrame.LocalVars().GetInt(0)
	value := math.Float32frombits(uint32(bits)) // todo
	jFrame.OperandStack().PushFloat(value)
}
